package com.wenyu.wenyuyuedu.activity.homepage;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Html;
import android.text.Selection;
import android.text.Spannable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.jingchen.pulltorefresh.PullToRefreshLayout;
import com.jingchen.pulltorefresh.PullableListView;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.adapter.homepagefragment.InvitationDetailAdapter;
import com.wenyu.wenyuyuedu.adapter.homepagefragment.Invitation_headview_adapter;
import com.wenyu.wenyuyuedu.adapter.homepagefragment.PlaytourCountAdapter;
import com.wenyu.wenyuyuedu.bean.homepager.Home_All_InvitationBean;
import com.wenyu.wenyuyuedu.bean.homepager.LikeBean;
import com.wenyu.wenyuyuedu.global.ApiWrapper;
import com.wenyu.wenyuyuedu.server.homepager.Homepage_All_Server;
import com.wenyu.wenyuyuedu.utils.AbSharedUtil;
import com.wenyu.wenyuyuedu.utils.MyToast;
import com.wenyu.wenyuyuedu.utils.SharedConstants;
import com.wenyu.wenyuyuedu.utils.StatusBarUtil;
import com.wenyu.wenyuyuedu.utils.TimeFormat;
import com.wenyu.wenyuyuedu.view.CircleImageView;
import com.wenyu.wenyuyuedu.view.NoScrollGridView;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.sharesdk.onekeyshare.OnekeyShare;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/*
* 帖子详情
* */
public class InvitationDetailActivity extends AppCompatActivity implements View.OnClickListener {
    Dialog dialog;
    @InjectView(R.id.invitation_left)
    ImageView invitationLeft;
    @InjectView(R.id.invitation_from_content)
    TextView invitationFromContent;
    @InjectView(R.id.invetation_content_view)
    PullableListView invetationContentView;
    @InjectView(R.id.invetation_refresh_view)
    PullToRefreshLayout invetationRefreshView;
    @InjectView(R.id.et_invitation)
    EditText etInvitation;
    @InjectView(R.id.tv_invitation)
    TextView tvInvitation;
    @InjectView(R.id.activity_invitation_detail)
    LinearLayout activityInvitationDetail;
    private Intent intent;
    private String invitationId;    //帖子的id，    从上一级的帖子列表传递过来
    private String circleName;      //圈子的名称     从上一级的帖子列表传递过来
    private String zanCount;        //评论的次数     用来判断该帖子是否可以被打赏（大于等于5）
    private View invitationHeadView;
    private ImageView invitationDown;   //向下的箭头
    private ImageView invitationShare;  //分享
    private ImageView invitationMessage;    //消息
    private ImageView invitationZan;    //点赞
    private CircleImageView invitationHead;     //头布局中的头像
    private TextView invitationPlaytour;
    private Dialog respotDialog;
    private ListView listView;
    private String id;
    /*用来标记随机数产生时停止数字变化*/
    private int page;
    private int money = 0;
    private InvitationDetailAdapter invitationDetailAdapter;
    private Dialog playtourDialog;
    private static final int SHOW_MONEY = 0;
    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SHOW_MONEY:
                    showMoney();
                    break;
            }
        }
    };
    private double[] arr;
    private TextView plautourMoney;
    private Dialog costomMoneyDialog;
    private NoScrollGridView gridView;
    private Invitation_headview_adapter headview_adapter;
    private Dialog fromDailog;
    private Dialog otherPeopleDialog;
    private int isMyCircle;
    private String headView;
    private TextView invitationNickName;
    private String nickName;
    private String creatTiem;
    private TextView releaseTime;
    private TextView invitationContent;
    private String invitationContent1;
    private String dateToString;
    private ImageView invitationDeity;
    private ArrayList<String> contentImageView;
    private ArrayList<String> imagesAll;
    private TextView playtour;
    private Home_All_InvitationBean body;
    private Home_All_InvitationBean.InfoBean info;
    /*点赞人的昵称*/
    private List<Home_All_InvitationBean.InfoBean.ForumBookmarkBean> forumBookmark;
    private TextView sc;
    private ImageView showZan;
    private String uid;
    private List<String> zanCount1;
    private Retrofit retrofit;
    private int sizes;
    private List<Home_All_InvitationBean.InfoBean.GivePathBean> give_path;
    private LinearLayout rlPlaytourContent;
    private NoScrollGridView gvPlaytourContent;
    private PlaytourCountAdapter playtourCountAdapter;
    private List<String> path;
    private TextView invitationShowPlaytour;
    private TextView invitationCommentCount;
    private String reply_num;
    /*帖子的id*/
    private String id2;
    /*发帖人的id*/
    private String uid1;
    /*评论的对方人的id*/
    private String id1;
    /*圈子的id*/
    private String object_id;
    private String token;
    private String userName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invitation_detail);
        StatusBarUtil.setStatusBar(InvitationDetailActivity.this,R.color.white);
        ButterKnife.inject(this);
        initView();
        listView = (ListView) invetationRefreshView.getPullableView();
        invetationRefreshView.setOnPullListener(new PullToRefreshLayout.OnPullListener() {
            @Override
            public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
                new Handler() {
                    public void handleMessage(Message msg) {
                        page++;
                        requesData();
                        //千万别忘了告诉控件刷新完毕了
                        invetationRefreshView.refreshFinish(PullToRefreshLayout.SUCCEED);
                    }
                }.sendEmptyMessageDelayed(0, 1000);
            }

            @Override
            public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
                new Handler() {
                    public void handleMessage(Message msg) {
                        //千万别忘了告诉控件刷新完毕了
                        invetationRefreshView.refreshFinish(PullToRefreshLayout.SUCCEED);
                    }
                }.sendEmptyMessageDelayed(0, 1000);
            }
        });

        /*初始化头布局*/
        initHeadView();
        invitationDetailAdapter = new InvitationDetailAdapter(InvitationDetailActivity.this,userName);
        listView.setAdapter(invitationDetailAdapter);
        requesData();
        /*listview条目的点击事件*/
        invetationContentView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (token == null) {
                    showLoginDoalog();

                } else {
                    /*/*token  必须要登陆才可以评价
                        parent_uid   发帖人的id
                        to_uid   帖子回复中被回复人的id
                        parent_id   帖子的id
                        post_id   圈子的id
                        content    评论内容 最低一个字符，最高1000个字符（500个汉字）
                        * */

                    /*帖子的id*/
                    id2 = info.getId();
                    /*发帖人的id*/
                    uid1 = info.getUid();
                    /*评论的对方人的id*/
                    id1 = info.getForumLzlReply().get(i).getId();
                    /*圈子的id*/
                    object_id = info.getObject_id();
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                    MyToast.showToast(InvitationDetailActivity.this, "当前是" + i, Toast.LENGTH_SHORT);
                    /*当前回复帖子人的昵称*/
                    String comment_name = info.getForumLzlReply().get(i).getComment_name();
                    etInvitation.setText("");
                    etInvitation.setText(Html.fromHtml("<font color= '#576b95'> 回复@</font>" + comment_name + ":"));
                    commentType = true;
                }

            }
        });
    }

    private void initHeadView() {
        invitationHeadView = getLayoutInflater().inflate(R.layout.invitation_detail_headview, null);
        invitationHeadViewOnclick();
        invetationContentView.addHeaderView(invitationHeadView);
        headview_adapter = new Invitation_headview_adapter(InvitationDetailActivity.this);
        gridView.setAdapter(headview_adapter);
        playtourCountAdapter = new PlaytourCountAdapter(InvitationDetailActivity.this);
        gvPlaytourContent.setAdapter(playtourCountAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                intent.setClass(InvitationDetailActivity.this, InvitationDeatil_HeadViewGridView_Viewpager_Activity.class);
                intent.putStringArrayListExtra("imagesViewpager", imagesAll);
                AbSharedUtil.putInt(InvitationDetailActivity.this, SharedConstants.IMAGE_INDEX, i);
                startActivity(intent);
            }
        });
    }

    /*请求网络数据*/
    private void requesData() {
        token = AbSharedUtil.getString(InvitationDetailActivity.this, SharedConstants.USER_TOKEN);
        Homepage_All_Server homepage_all_server = ApiWrapper.getInstance().create(Homepage_All_Server.class);
        Call<Home_All_InvitationBean> invitationDetail = homepage_all_server.getInvitationDetail(token, invitationId, page + "");
        invitationDetail.enqueue(new Callback<Home_All_InvitationBean>() {
            @Override
            public void onResponse(Call<Home_All_InvitationBean> call, Response<Home_All_InvitationBean> response) {
                body = response.body();
                String msg = body.getMsg();
                if (body == null) {
                    return;
                } else {
                    int code1 = body.getCode();
                    if (code1 == 1) {
                        info = body.getInfo();
                        /*帖子的ID*/
                        uid = info.getId();
                        /*发帖人的昵称*/
                        userName = info.getMember().getNickname();
                        /*帖子的点赞数量*/
                        zanCount = info.getSupport_num();
                        /*帖子的评论数量*/
                        reply_num = info.getReply_num();
                        List<String> images = info.getImages();
                        headview_adapter.addAll(images);
                        /*打赏人的头像*/
                        give_path = info.getGive_path();
                        fillPlaytourView();
                        /*点赞人数的集合*/
                        forumBookmark = info.getForumBookmark();

                        fillHeadViewData();
                        invitationDetailAdapter.updateRes(info.getForumLzlReply());
                        playtourCountAdapter.addPlaytourAll(path);
                    } else if (code1 == 0) {
                        showLoginDoalog();
                    }
                }


            }

            @Override
            public void onFailure(Call<Home_All_InvitationBean> call, Throwable t) {
                MyToast.showToast(InvitationDetailActivity.this, "网络异常，请稍后重试", Toast.LENGTH_SHORT);

            }
        });
    }

    /*填充打赏人的头像*/
    private void fillPlaytourView() {
        path = new ArrayList<>();
        if (give_path != null) {
            for (int paths = 0; paths < give_path.size(); paths++) {
                String path1 = give_path.get(paths).getPath();
                path.add(path1);
            }
        }
        if (path.size() > 7) {

        }
    }

    /*填充头布局数据*/
    private void fillHeadViewData() {
        Glide.with(InvitationDetailActivity.this)
                .load(headView)
                .into(invitationHead);
        invitationNickName.setText(nickName);
        invitationFromContent.setText(circleName);
        releaseTime.setText(dateToString);
        invitationContent.setText(invitationContent1);
        if (Integer.parseInt(reply_num) > 0) {
            invitationCommentCount.setVisibility(View.VISIBLE);
            invitationCommentCount.setText(reply_num + "人已评论");
        }

        if (path.size() > 0) {
            invitationShowPlaytour.setText("等" + path.size() + "人已赏");
            invitationShowPlaytour.setVisibility(View.VISIBLE);
        }
        int i = Integer.parseInt(zanCount);
        /*点赞*/
        showZan.setVisibility(i > 0 ? View.VISIBLE : View.INVISIBLE);

        if (i < 5) {
            invitationDeity.setVisibility(View.INVISIBLE);
            playtour.setVisibility(View.INVISIBLE);
            //showZan.setVisibility(View.INVISIBLE);
        } else {
            invitationDeity.setVisibility(View.VISIBLE);
            playtour.setVisibility(View.VISIBLE);
        }
        AlertLikeCount();
    }

    /*修改点赞的人数显示*/
    private void AlertLikeCount() {
        if (forumBookmark != null) {
            for (int zan = 0; zan < forumBookmark.size(); zan++) {
                String nickname = forumBookmark.get(zan).getNickname();
                zanCount1.add(nickname);
                sizes = zanCount1.size();
            }
            if (forumBookmark != null) {
                int size = zanCount1.size() > 12 ? 12 : sizes;
                StringBuilder sb = new StringBuilder();

                for (int j = 0; j < size; j++) {
                    if (j != size - 1) {
                        sb.append(zanCount1.get(j) + ",");
                    } else {
                        sb.append(zanCount1.get(j));
                    }
                }
                if (zanCount1.size() > 12) {
                    sb.append("等" + zanCount1.size() + "人已赞");
                }
                sc.setText(sb.toString());
            }
        }


    }

    /*
    * 头布局的点击事件
    * */
    private void invitationHeadViewOnclick() {
        invitationDown = (ImageView) invitationHeadView.findViewById(R.id.invitation_down);
        invitationShare = (ImageView) invitationHeadView.findViewById(R.id.invitation_share);
        invitationMessage = (ImageView) invitationHeadView.findViewById(R.id.invitation_message);
        invitationZan = (ImageView) invitationHeadView.findViewById(R.id.invitation_zan);
        invitationDeity = (ImageView) invitationHeadView.findViewById(R.id.invitation_deity);
        invitationHead = (CircleImageView) invitationHeadView.findViewById(R.id.invitation_head);
        invitationPlaytour = (TextView) invitationHeadView.findViewById(R.id.invitation_playtour);
        invitationNickName = (TextView) invitationHeadView.findViewById(R.id.invitation_nickname);
        releaseTime = (TextView) invitationHeadView.findViewById(R.id.invitation_releasetime);
        invitationContent = (TextView) invitationHeadView.findViewById(R.id.invitation_content);
        invitationShowPlaytour = (TextView) invitationHeadView.findViewById(R.id.invitation_show_playtour);
        gvPlaytourContent = (NoScrollGridView) invitationHeadView.findViewById(R.id.gv_playtour_content);
        invitationCommentCount = (TextView) invitationHeadView.findViewById(R.id.invitation_comment_count);
        playtour = (TextView) invitationHeadView.findViewById(R.id.invitation_playtour);
        showZan = (ImageView) invitationHeadView.findViewById(R.id.invitation_show_zan);
        sc = (TextView) invitationHeadView.findViewById(R.id.invitation_show_content);
        gridView = (NoScrollGridView) invitationHeadView.findViewById(R.id.invitation_picture_content);
        invitationDown.setOnClickListener(this);
        invitationShare.setOnClickListener(this);
        invitationMessage.setOnClickListener(this);
        invitationZan.setOnClickListener(this);
        invitationHead.setOnClickListener(this);
        invitationPlaytour.setOnClickListener(this);

    }

    /*
    * 初始化数据
    * */
    private void initView() {
        intent = getIntent();
        zanCount1 = new ArrayList<>();
        invitationId = intent.getStringExtra("invitationId");
        circleName = intent.getStringExtra("circlename");
        headView = intent.getStringExtra("headView");
        nickName = intent.getStringExtra("niacName");
        creatTiem = intent.getStringExtra("creatTime");
        Long aLong = Long.valueOf(creatTiem);
        dateToString = TimeFormat.getDateToString(aLong);
        invitationContent1 = intent.getStringExtra("invitationContent");
        invitationLeft.setOnClickListener(this);
        etInvitation.addTextChangedListener(new MyEditTextChangeListener());
        invitationFromContent.setOnClickListener(this);
        imagesAll = intent.getStringArrayListExtra("images");
    }

    private CharSequence temp;
    /*判断是直接对帖子评论还是回复评论   false 是回复评论    true 是对帖子直接评论*/
    private boolean commentType = false;

    private class MyEditTextChangeListener implements TextWatcher {
        /*内容发生变化时*/
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            tvInvitation.setText("发表");
            tvInvitation.setTextSize(18);
            tvInvitation.setPadding(20, 4, 20, 4);
            tvInvitation.setClickable(false);
            tvInvitation.setBackgroundResource(R.drawable.invitation_publishs_shape);
            tvInvitation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (commentType) {
                        /*token  必须要登陆才可以评价
                        parent_uid   发帖人的id
                        to_uid   帖子回复中被回复人的id
                        parent_id   帖子的id
                        post_id   圈子的id
                        content    评论内容 最低一个字符，最高1000个字符（500个汉字）
                        * */
                        /*点条目时触发*/

                        String reply = etInvitation.getText().toString();

                        publicData();
                        MyToast.showToast(InvitationDetailActivity.this, "评论:" + reply, Toast.LENGTH_SHORT);
                    } else {
                        /*点帖子时触发*/

                        String comment = etInvitation.getText().toString();
                        MyToast.showToast(InvitationDetailActivity.this, "评论内容" + comment, Toast.LENGTH_SHORT);
                    }
                    etInvitation.setText("");
                }
            });
        }

        /*
        *编辑框的内容正在发生改变时的回调方法 >>用户正在输入
        * 我们可以在这里实时地 通过搜索匹配用户的输入
        * */
        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            CharSequence text = etInvitation.getText();
            if (text instanceof Spannable) {
                Spannable spanText = (Spannable) text;
                Selection.setSelection(spanText, text.length());
                if (charSequence.length() == 0) {
                    tvInvitation.setText("发表");
                    tvInvitation.setBackgroundResource(R.drawable.invitation_publish_shape);
                    tvInvitation.setTextColor(getResources().getColor(R.color.white));
                    tvInvitation.setClickable(false);
                    tvInvitation.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            MyToast.showToast(InvitationDetailActivity.this, "请输入内容", Toast.LENGTH_SHORT);

                        }
                    });
                } else {

                    tvInvitation.setText("发表");
                    tvInvitation.setClickable(true);

                    tvInvitation.setBackgroundResource(R.color.red);

                }
            }

        }

        /*
        * 编辑框的内容改变以后,用户没有继续输入时 的回调方法
        * */
        @Override
        public void afterTextChanged(Editable editable) {
        }
    }

    /*发表的接口*/
    private void publicData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //返回
            case R.id.invitation_left:
                finish();
                break;
            /*又上角的来自*/
            case R.id.invitation_from_content:
                isMyInvitation();
                break;
            /*
            * 头像
            * */
            case R.id.invitation_head:
                MyToast.showToast(InvitationDetailActivity.this, "头像", Toast.LENGTH_SHORT);
                break;
            /*
            * 向下的
            * */
            case R.id.invitation_down:
                showDialog();
                break;
            /*
            * 分享
            * */
            case R.id.invitation_share:
                showShare();
                break;
            /*
            * 点赞
            * */
            case R.id.invitation_zan:
                if (token == null) {
                    showLoginDoalog();
                } else {
                    final String nickname = AbSharedUtil.getString(InvitationDetailActivity.this, SharedConstants.USER_NICKNAME);
                    int i = Integer.parseInt(uid);
                    int type = 1;
                    retrofit = new Retrofit.Builder()
                            .baseUrl("http://www.iwenyu.cn/forum/index/dobookmark.html/")
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                    Homepage_All_Server homepage_all_server1 = retrofit.create(Homepage_All_Server.class);
                    Call<LikeBean> like1 = homepage_all_server1.getLike(token, i, 1);
                    like1.enqueue(new Callback<LikeBean>() {
                        @Override
                        public void onResponse(Call<LikeBean> call, Response<LikeBean> response) {
                            LikeBean body = response.body();
                            if (body != null) {
                                int code = body.getCode();
                                if (code == 1) {
                                    MyToast.showToast(InvitationDetailActivity.this, "点赞成功", Toast.LENGTH_SHORT);
                                    zanCount1.clear();
                                    zanCount1.add(0, nickname);
                                    AlertLikeCount();
                                    invitationDetailAdapter.notifyDataSetChanged();
                               /* zanCount1.add(nickname);
                                dianZan();*/
                                } else if (code == 0) {
                                    MyToast.showToast(InvitationDetailActivity.this, "token错误或者已失效", Toast.LENGTH_SHORT);
                                } else if (code == 2300) {
                                    MyToast.showToast(InvitationDetailActivity.this, "需要点赞之后才可以操作（点赞和踩）", Toast.LENGTH_SHORT);
                                } else if (code == 2301) {
                                    MyToast.showToast(InvitationDetailActivity.this, "抱歉您的账户被暂时限制了，无法进行此操作", Toast.LENGTH_SHORT);
                                } else if (code == 2303) {
                                    MyToast.showToast(InvitationDetailActivity.this, "系统繁忙，请稍后再试", Toast.LENGTH_SHORT);
                                } else if (code == 2302) {
                                    MyToast.showToast(InvitationDetailActivity.this, "您已经操作过了!", Toast.LENGTH_SHORT);
                                } else if (code == 2304) {
                                    MyToast.showToast(InvitationDetailActivity.this, "该帖子不存在或者被冻结", Toast.LENGTH_SHORT);
                                } else if (code == 2305) {
                                    MyToast.showToast(InvitationDetailActivity.this, "该回复不存在或者已经被屏蔽", Toast.LENGTH_SHORT);
                                }
                            }
                        }

                        @Override
                        public void onFailure(Call<LikeBean> call, Throwable t) {
                            MyToast.showToast(InvitationDetailActivity.this, "系统繁忙，请稍后再试", Toast.LENGTH_SHORT);
                        }
                    });
                }
                break;
            /*
            * 消息
            * */
            case R.id.invitation_message:
                if (token == null) {
                    showLoginDoalog();
                } else {
                    //TextView tv = new TextView(InvitationDetailActivity.this);
                    //tv.setText(Html.fromHtml("<font color='red'>我叫小明：</font>哈哈哈"));
                    commentType = false;
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                     /*帖子的id*/
                    id2 = info.getId();
                    /*发帖人的id*/
                    uid1 = info.getUid();
                    /*圈子的id*/
                    object_id = info.getObject_id();
                    /*当前发帖人的昵称*/
                    String nickname1 = info.getMember().getNickname();
                    etInvitation.setText("");
                    etInvitation.setFocusable(true);
                    etInvitation.setText(Html.fromHtml("<font color= '#576b95'> 评论@</font>" + nickname1 + ":"));
                }

                break;
            /*
            * 打赏
            * */
            case R.id.invitation_playtour:
                PlaytoueDialog();
                break;
            /*收藏*/
            case R.id.collect:

                break;
            /*举报*/
            case R.id.report:
                // reportDialog();
                break;
            /*
            * 删除
            * */
            case R.id.delete:

                break;
        }
    }

    /*用来判断是自己的圈子还是别人的圈子，（显示的dailog样式是不一样的）*/
    private void isMyInvitation() {
        showFromOtherPeopleDialog();
    }

    /*右上角来自的dialog----别人的圈子*/
    private void showFromOtherPeopleDialog() {
        View view = getLayoutInflater().inflate(R.layout.invitation_from_otherpeople_dialog,
                null);
        otherPeopleDialog = new Dialog(this, R.style.transparentFrameWindowStyle);
        this.otherPeopleDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = this.otherPeopleDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        this.otherPeopleDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        this.otherPeopleDialog.setCanceledOnTouchOutside(true);
        this.otherPeopleDialog.show();
    }

    /*来自其他人的圈子的dailog的取消*/
    public void otherpeople_cancel(View view) {
        otherPeopleDialog.cancel();
    }

    /*来自其他人的圈子的dailog的分享*/
    public void btn_otherpeople_share(View view) {
        showShare();
    }

    /*来自其他人的圈子的dailog的举报*/
    public void btn_report_otherpeople_circle(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "举报", Toast.LENGTH_SHORT);
    }

    /*来自其他人的圈子的dailog的查看书圈*/
    public void btn_examine_circle(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "查看书圈", Toast.LENGTH_SHORT);
    }

    /*来自其他人的圈子的dailog的退出圈子*/
    public void btn_quit_circle_manage(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "退出圈子", Toast.LENGTH_SHORT);
    }

    /*右上角来自的dialog----我的圈子*/
    private void showFromDialog() {
        View view = getLayoutInflater().inflate(R.layout.invitation_from_dialog,
                null);
        fromDailog = new Dialog(this, R.style.transparentFrameWindowStyle);
        this.fromDailog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = this.fromDailog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        this.fromDailog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        this.fromDailog.setCanceledOnTouchOutside(true);
        this.fromDailog.show();
    }

    /*来自我的圈子的dailog的取消*/
    public void from_cancel(View view) {
        fromDailog.cancel();

    }

    /*来自dailog的分享*/
    public void btn_share(View view) {
        showShare();
    }

    /*来自dailog的编辑书圈*/
    public void btn_edite_circle(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "编辑书圈", Toast.LENGTH_SHORT);
    }

    /*来自dailog的成员管理*/
    public void btn_member_manage(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "成员管理", Toast.LENGTH_SHORT);
    }

    /*显示钱数*/
    public void showMoney() {
        money++;
        int index = (int) (Math.random() * arr.length);
        double v = arr[index];
        plautourMoney.setText(v + "");
        handler.sendEmptyMessageDelayed(SHOW_MONEY, 100);
        if (money == 200) {
            handler.removeCallbacksAndMessages(null);
            money = 0;
        }
    }

    /*随机打赏*/
    private void PlaytoueDialog() {
        View view = getLayoutInflater().inflate(R.layout.playtour_random_dialog,
                null);
        //1.0、1.23、2.0、2.22、2.68、3.0、3.88、5.20、6.66、6.88、8.88、8.66、9.99
        plautourMoney = (TextView) view.findViewById(R.id.tv_playtour_money);
        arr = new double[]{1.0, 1.23, 2.0, 2.22, 2.68, 3.0, 3.88, 5.20, 6.66, 6.88, 8.66, 9.99};
        for (int j = 1; j < arr.length; j++) {
            handler.sendEmptyMessage(SHOW_MONEY);
            System.out.println("InvitationDetailActivity: j" + j);
        }
        playtourDialog = new Dialog(this, R.style.transparentFrameWindowStyle);
        playtourDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = playtourDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        playtourDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        playtourDialog.setCanceledOnTouchOutside(true);
        playtourDialog.show();
    }

    /*自定义打赏*/
    public void playtourCancle(View view) {
        costomMoneyDialog.cancel();
    }

    /*随机打赏取消*/
    public void playtourCancles(View view) {
        playtourDialog.cancel();

        handler.removeCallbacksAndMessages(null);
    }

    /*调起微信*/
    public void tv_playtour(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "调起微信", Toast.LENGTH_SHORT);
    }

    /*调起微信*/
    public void tv_costam(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "自定义金额", Toast.LENGTH_SHORT);
    }

    /*其他金额*/
    public void tv_playtour_else(View view) {
        costomMoneyDialog();
        playtourDialog.cancel();
    }

    /*自定义金额中的取消*/
    public void tv_costam_else(View view) {
        PlaytoueDialog();
        costomMoneyDialog.cancel();
    }

    /*自定义金额的dialog*/
    private void costomMoneyDialog() {
        View view = getLayoutInflater().inflate(R.layout.constom_money_dialog,
                null);
        costomMoneyDialog = new Dialog(this, R.style.transparentFrameWindowStyle);
        costomMoneyDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = costomMoneyDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        costomMoneyDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        costomMoneyDialog.setCanceledOnTouchOutside(true);
        costomMoneyDialog.show();
    }

    /*举报的列表*/
    private void reportDialog() {
        View view = getLayoutInflater().inflate(R.layout.invitation_report_dialog,
                null);
        respotDialog = new Dialog(this, R.style.transparentFrameWindowStyle);
        respotDialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = respotDialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        respotDialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        respotDialog.setCanceledOnTouchOutside(true);
        respotDialog.show();
    }

    /*收藏*/
    public void advertising_grabage(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "收藏", Toast.LENGTH_SHORT);
    }

    public void plagiarize(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "抄袭", Toast.LENGTH_SHORT);
    }

    public void hostility(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "不友善", Toast.LENGTH_SHORT);
    }

    public void break_the_law(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "违法", Toast.LENGTH_SHORT);
    }

    public void other(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "其他", Toast.LENGTH_SHORT);
    }

    public void report_cancel(View view) {
        respotDialog.cancel();
        MyToast.showToast(InvitationDetailActivity.this, "取消", Toast.LENGTH_SHORT);
    }

    private void showDialog() {
        View view = getLayoutInflater().inflate(R.layout.invitation_down_dialog,
                null);
        dialog = new Dialog(this, R.style.transparentFrameWindowStyle);
        dialog.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        Window window = dialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.main_menu_animstyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        dialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();
    }

    /*取消*/
    public void on_click(View view) {
        dialog.cancel();
    }

    /*收藏*/
    public void collect(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "收藏", Toast.LENGTH_SHORT);
    }

    /*举报*/
    public void report(View view) {
        reportDialog();
    }

    /*删除*/
    public void delete(View view) {
        MyToast.showToast(InvitationDetailActivity.this, "删除", Toast.LENGTH_SHORT);
    }

    private void showShare() {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        // title标题，印象笔记、邮箱、信息、微信、人人网、QQ和QQ空间使用
        oks.setTitle("标题");
        // titleUrl是标题的网络链接，仅在Linked-in,QQ和QQ空间使用
        oks.setTitleUrl("http://sharesdk.cn");
        // text是分享文本，所有平台都需要这个字段
        oks.setText("我是分享文本");
        //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
        oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl("http://sharesdk.cn");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("我是测试评论文本");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite("ShareSDK");
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl("http://sharesdk.cn");

// 启动分享GUI
        oks.show(this);
    }

    @Override
    protected void onDestroy() {
        handler.removeCallbacksAndMessages(null);
        super.onDestroy();
    }

    android.app.AlertDialog ad;
    private TextView quxiao;
    private TextView queding;

    /*显示登陆的dialog*/
    private void showLoginDoalog() {

        ad = new android.app.AlertDialog.Builder(InvitationDetailActivity.this).create();
        ad.show();
        Window window = ad.getWindow();
        window.setContentView(R.layout.dailog_login);
        quxiao = (TextView) window.findViewById(R.id.dialog_login_quxiao);
        queding = (TextView) window.findViewById(R.id.dialog_login_queding);
        quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ad.dismiss();
            }
        });
        queding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ad.dismiss();
            }
        });
    }
}
